let model = require("../Model");

let infoMock = require("../mock/infoMock.js");
const { get } = require("../Model/addSchema");

/**
 * 添加的测试数据
 */
// async function addInfo() { 
//   let data = await model.infoModel.insertMany(infoMock);
//   console.log(data);
// }
// addInfo(); 

//得到数据

async function getInfo(filter, page = 1, limit = 10) { 
    let date = await model.infoModel
      .find(filter)
      .skip((page - 1) * limit)
      .limit(limit);
 return (date);
  } 


//删除
async function deleteInfo(id){
let data=await model.infoModel.deleteOne({_id:id});
return data;
}


// // 添加
async function addInfo(info){
    let data=await model.infoModel.create(info);
    return data;
}



//修改
async function alterInfo(info){
    if(!info||!info.id) return null;
    let data=await model.infoModel.updateMany(
        {_id:info.id},
        info,
        )
        return data;
}

//数据总条数
async function Count(filter){
  let data=await model.infoModel.find(filter).count();
  return data;
}

module.exports.getInfo=getInfo;
module.exports.deleteInfo=deleteInfo;
module.exports.addInfo=addInfo;
module.exports.alterInfo=alterInfo;
module.exports.Count=Count;



